package com.xiaoyaoji.admin.controller;


import com.sun.istack.internal.NotNull;
import com.xiaoyaoji.common.util.JsonResult;
import com.xiaoyaoji.admin.service.IDocService;
import com.xiaoyaoji.postman.pojo.dto.PostmanDTO;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LiYaCai
 * @since 2020-06-11
 */
@RestController
@RequestMapping("/doc")
public class DocController {

    @Autowired
    private IDocService docService;

//    @ApiOperation("导入txt文件")
//    @ApiImplicitParams(value = {
//            @ApiImplicitParam(name = "projectId", value = "项目id", dataType = "String", required = true),
//            @ApiImplicitParam(name = "parentId", value = "父目录id", dataType = "String", required = true),
//            @ApiImplicitParam(name = "file", value = "txt文件", dataType = "__file", required = true)
//    })
//    @PostMapping("/txt/import")
    public JsonResult importTxtDoc(@RequestParam @NotNull String projectId,
                                   @RequestParam @NotNull String parentId,
                                   @RequestParam @NotNull MultipartFile file) throws Exception {
        docService.importTxtDoc(projectId, parentId, file);
        return JsonResult.success();
    }

    @ApiOperation("导出Postman.json文件")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "parentId", value = "父目录id", dataType = "String", required = true)
    })
    @GetMapping("/postman/export")
    public PostmanDTO exportPostmanJson(@RequestParam @NotNull String parentId) {
        return docService.exportPostmanJson(parentId);
    }

    @ApiOperation("获取响应json")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "接口id", dataType = "String", required = true)
    })
    @GetMapping("/get")
    public String getResponseJson(@RequestParam @NotNull String id) {
        return docService.getResponseJson(id);
    }

}

